﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Text;
using System.Threading.Tasks;

namespace chapt1_3Example
{
    class Program
    {
        static void Main(string[] args)
        {
            //基址
            Uri baseAddress = new Uri("http://localhost:500");
            using (ServiceHost host = new ServiceHost(typeof(MyService), baseAddress))
            {
                //公开服务的元数据
                ServiceMetadataBehavior metadata = null;
                host.Description.Behaviors.Find<ServiceMetadataBehavior>();
                if (metadata == null)
                {
                    metadata = new ServiceMetadataBehavior();
                }
                metadata.HttpGetEnabled = true; //必须
                host.Description.Behaviors.Add(metadata);
                

                //打开服务
                host.Open();
                Console.WriteLine("服务已启动.");

                Console.Read();
                host.Close();   //关闭服务
            }
        }
    }
}
